
import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

public class logger {
	
	private Logger logger;
	private FileHandler fileHandler;
	
	//constructor
	public logger(String filename) throws SecurityException, IOException{
	  LogManager lm = LogManager.getLogManager();
      Logger logger;
      FileHandler fh = new FileHandler(filename,1000000,1,true);
      logger = Logger.getLogger("LoggingExample1");
      lm.addLogger(logger);
      logger.setLevel(Level.INFO);
      fh.setFormatter(new SimpleFormatter());
      logger.addHandler(fh);
      this.setLogger(logger);
      this.setFileHandler(fh);

	}
	
	/*logs a message, two severiy options:
	 * 1==info
	 * 2==severe
	 */
	public void log(int level,String logMessage){
			if (level==2) this.logger.log(Level.SEVERE,logMessage);
			if (level==1) this.logger.log(Level.INFO,logMessage);
	}
	
	//closes the file handler
	public void closeFileHandler(){
		try
		{
			fileHandler.close();
		}
		catch (Exception e){
			this.log(2,"can not close file handler");
		};
		
	}

	public void setLogger(Logger logger) {
		this.logger = logger;
	}

	public Logger getLogger() {
		return logger;
	}

	public void setFileHandler(FileHandler fileHandler) {
		this.fileHandler = fileHandler;
	}

}


